package com.ruoyi.machine.advanced.repair.apply.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.machine.advanced.repair.apply.domain.RepairApply;
import com.ruoyi.machine.advanced.repair.apply.service.IRepairApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备维修申请表
 * 控制层
 */
@RestController
@RequestMapping("/machine/repair/apply")
@Api(value = "设备维修申请模块", tags = "设备维修申请接口")
public class RepairApplyController extends BaseController {

    @Autowired
    private IRepairApplyService repairApplyService;

    /**
     * 获取设备维修申请表列表
     * @param repairApply
     * @return
     */
    @ApiOperationSupport(includeParameters = {"RepairApply.machineId", "RepairApply.repairApplyId"})
    @ApiOperation(value = "获取设备维修申请表列表",notes = "查询所有设备维修申请表信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RepairApply repairApply) {

        startPage();

        List<RepairApply> repairApplyList = repairApplyService.selectRepairApplyList(repairApply);

        return getDataTable(repairApplyList);
    }

    /**
     * 导出设备维修申请表
     * @param repairApply
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody RepairApply repairApply) {

        List<RepairApply> repairApplyList = repairApplyService.selectRepairApplyList(repairApply);

        ExcelUtil<RepairApply> util = new ExcelUtil<>(RepairApply.class);

        return util.exportExcel(repairApplyList, "设备维修申请数据");
    }

    /**
     * 新增设备维修申请表
     * @param repairApply
     * @return
     */
    @ApiOperation(value = "新增设备维修申请表", notes = "新增设备维修申请表")
    @ApiImplicitParam(name = "repairApply", value = "新增设备维修申请表", dataType = "RepairApply")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody RepairApply repairApply) {
        return toAjax(repairApplyService.insertRepairApply(repairApply));
    }

    /**
     * 修改设备维修申请表
     * @param repairApply
     * @return
     */
    @ApiOperation(value = "修改设备维修申请表", notes = "修改设备维修申请表")
    @ApiImplicitParam(name = "repairApply", value = "修改设备维修申请表", dataType = "RepairApply")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody RepairApply repairApply) {
        return toAjax(repairApplyService.updateRepairApply(repairApply));
    }

    /**
     * 删除设备维修申请表
     * 仅修改删除标志位
     * @param repairApply
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody RepairApply repairApply) {
        return toAjax(repairApplyService.updateRepairApplyDeleteFlag(repairApply));
    }
}
